/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ing.sisval.da;

import java.sql.Connection;
import java.util.ArrayList;
import org.ing.sisval.be.BEInfraestructura;
import org.rx.cr.dao.DAOAbstract;

/**
 *
 * @author Mysham
 */
public class DAInfraestructura extends DAOAbstract<BEInfraestructura> {

    public DAInfraestructura(Connection conn) {
        setConnection(conn);
    }

    @Override
    public int registrar(BEInfraestructura be) throws Exception {
        try {
            setStoreProcedure("SISVAL.sp_ins_infraestructura");
            setParameterString(be.getNombre());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int actualizarRegistro(BEInfraestructura be) throws Exception {
        try {
            setStoreProcedure("SISVAL.sp_upd_infraestructura");
            setParameterInt(be.getInfraestructuraid());
            setParameterString(be.getNombre());

            return Integer.parseInt(commit().toString());
        } catch (Exception e) {
            return rollback(e);
        }
    }

    @Override
    public int eliminarRegistro(BEInfraestructura tipo) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ArrayList<BEInfraestructura> buscarReferencia(String string) throws Exception {
        try {
            clear();
            setStoreProcedure("SISVAL.sp_sel_infraestructura");
            setParameterString(string);
            commitc();
            while (existResult()) {
                BEInfraestructura be = new BEInfraestructura();
                be.setInfraestructuraid(getDataInt(1));
                be.setNombre(getDataString(2));

                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public ArrayList<BEInfraestructura> listar() throws Exception {
        try {
            clear();
            setStoreProcedure("SISVAL.sp_sel_infraestructura");
            setParameterString("");
            commitc();
            while (existResult()) {
                BEInfraestructura be = new BEInfraestructura();
                be.setInfraestructuraid(getDataInt(1));
                be.setNombre(getDataString(2));

                add(be);
            }
            return getLista();
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

    @Override
    public BEInfraestructura buscar(int i) throws Exception {
        try {
            BEInfraestructura be = null;
            setStoreProcedure("SISVAL.sp_sel_infraestructura_id");
            setParameterInt(i);
            commitc();
            while (existResult()) {
                be = new BEInfraestructura();
                be.setInfraestructuraid(getDataInt(1));
                be.setNombre(getDataString(2));
                add(be);

            }
            return be;
        } catch (Exception e) {
            rollback(e);
            return null;
        }
    }

//    // @Override
//    public ArrayList<BEInfraestructura> listar(int i) throws Exception {
//        try {
//            clear();
//            setStoreProcedure("SISVAL.sp_sel_infraestructura");
//            setParameterInt(i);
//            commitc();
//            while (existResult()) {
//                BEInfraestructura be = new BEInfraestructura();
//                be.setInfraestructuraid(getDataInt(1));
//                be.setNombre(getDataString(2));
//
//                add(be);
//            }
//            return getLista();
//        } catch (Exception e) {
//            rollback(e);
//            return null;
//        }
//    }
//
//    //@Override
//    public int eliminarRegistro(int infraestructuraid) throws Exception {
//        try {
//            setStoreProcedure("SISVAL.sp_del_infraestructura");
//            setParameterInt(infraestructuraid);
//
//            return Integer.parseInt(commit().toString());
//        } catch (Exception e) {
//            return rollback(e);
//        }
//    }

}
